package com.monodaipoly.perfil;




import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

public class Perfil extends Activity{
	//private BaseDatosDbAdapter mDbHelper;
	private Long mId;
	private String mNick;
	private String mFecha;
	private TextView mTexto;
	private TextView mTexto2;
	private static final int MODIFICAR_ID = Menu.FIRST;
	private static final int AVATAR_ID = Menu.FIRST + 1;
	BDglobal bdglobal;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.perfil);
        bdglobal=((BDglobal) getApplicationContext());
		
		cargarDatos();
		
		Toast.makeText(getApplicationContext(), "Nick recibido: " + mNick, Toast.LENGTH_LONG).show();
		
	}
	
	
	
	 @Override
	    public boolean onCreateOptionsMenu(Menu menu) {
	        super.onCreateOptionsMenu(menu);
	        menu.add(0, MODIFICAR_ID, 0, R.string.modificar_menu);
	        menu.add(0, AVATAR_ID, 0, "elegir avatar");
	        return true;
	    }

	    @Override
	    public boolean onMenuItemSelected(int featureId, MenuItem item) {
	        switch(item.getItemId()) {
	            case MODIFICAR_ID:
	                Intent i= new Intent(this,ModificarDatos.class);
	                i.putExtra("nick", mNick);
	                //startActivity(i);
	                startActivityForResult(i, 0);
	                
	                cargarDatos();
	                return true;
	            case AVATAR_ID:
	            	Intent in=new Intent(this,ElegirAvatar.class);
	                startActivity(in);
	                //startActivityForResult(i, 0);
	                return true;
	        }

	        return super.onMenuItemSelected(featureId, item);
	    }

	public void cargarDatos(){
		Bundle b= getIntent().getExtras();
		mId = b.getLong("id");
		Cursor c=bdglobal.getBaseDatosBD().fetchUsuario(mId);
		c.moveToFirst();
		mNick=c.getString(c.getColumnIndex(BaseDatosDbAdapter.KEY_NICK));
		mFecha=c.getString(c.getColumnIndex(BaseDatosDbAdapter.KEY_FECHA));
		mTexto=(TextView) findViewById(R.id.textView2);
		mTexto.setText(mNick);
		mTexto2=(TextView) findViewById(R.id.textView4);
		mTexto2.setText(mFecha);
		
	}



	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		cargarDatos();
		
	}
	
	
	
}
